# coding=utf-8
# 本题为考试多行输入输出规范示例，无需提交，不计分。
import sys
from typing import List
from collections import defaultdict


def getRes(samples: List[List]):
    # find the longest road
    n = len(samples)
    count = 0
    record_dict = defaultdict(int)  # 自动赋值为0
    for i in range(n):
        for j in range(len(samples[i])):
            record_dict[samples[i][j]] += 1
    for key, value in record_dict.items():
        if value == n:
            count += 1
    return count


if __name__ == "__main__":
    # 读取第一行的n
    n = int(sys.stdin.readline().strip())
    values = []
    for i in range(n):
        m = int(sys.stdin.readline().strip())
        value = []
        for j in range(m):
            # 读取每一行
            line = sys.stdin.readline().strip()
            # 把每一行的数字分隔后转化成int列表
            temp_value = list(map(int, line.split()))
            temp_value.pop(0)
            value.append(temp_value)
        values.append(value)
    ans = []
    for i in range(n):
        print(getRes(values[i]))
